﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QDoubleSpinBox"
#include "QDoubleSpinBox"
#include "QRadioButton"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;

#include "qt_graphics_view_image.h"
#include "qt_graphics_shape_rectangle.h"





//#include <fstream>
//#include "nlohmann/json.hpp"
//using json = nlohmann::json;
//QSettings* m_qsettings;

class MeasureElectrode :public QDialog
{
public:
    QSettings* m_qsettings;

    QString m_section   = "";

    MyQGraphicsView* m_view ;

    QLabel* m_qlabel_row1_offset;
    QSpinBox* m_SpinBox_row1_offset;

    QLabel* m_qlabel_row2_offset;
    QSpinBox* m_SpinBox_row2_offset;

    QLabel* m_qlabel_column1_offset;
    QSpinBox* m_SpinBox_column1_offset;

    QLabel* m_qlabel_column2_offset;
    QSpinBox* m_SpinBox_column2_offset;



    QLabel* m_qlabel_measure_number;
    QSpinBox* m_SpinBox_measure_number;

    QLabel* m_qlabel_left_height_low;
    QDoubleSpinBox* m_QDoubleSpinBox_left_height_low;

    QLabel* m_qlabel_left_height_high;
    QDoubleSpinBox* m_QDoubleSpinBox_left_height_high;

    QLabel * m_qlabel_left_width_low;
    QDoubleSpinBox * m_QDoubleSpinBox_left_width_low;

    QLabel * m_qlabel_left_width_high;
    QDoubleSpinBox * m_QDoubleSpinBox_left_width_high;

    QLabel* m_qlabel_right_height_low;
    QDoubleSpinBox* m_QDoubleSpinBox_right_height_low;

    QLabel* m_qlabel_right_height_high;
    QDoubleSpinBox* m_QDoubleSpinBox_right_height_high;

    QLabel * m_qlabel_right_width_low;
    QDoubleSpinBox * m_QDoubleSpinBox_right_width_low;

    QLabel * m_qlabel_right_width_high;
    QDoubleSpinBox * m_QDoubleSpinBox_right_width_high;


    QLabel* m_qlabel_total_height_low;
    QDoubleSpinBox* m_QDoubleSpinBox_total_height_low;

    QLabel* m_qlabel_total_height_high;
    QDoubleSpinBox* m_QDoubleSpinBox_total_height_high;

    QLabel * m_qlabel_total_width_low;
    QDoubleSpinBox * m_QDoubleSpinBox_total_width_low;

    QLabel * m_qlabel_total_width_high;
    QDoubleSpinBox * m_QDoubleSpinBox_total_width_high;



    QLabel * m_qlabel_ratio;
    QDoubleSpinBox  * m_qdoublespinbox_ratio;

    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

    QLabel* m_qlabel_message;

    int m_result,m_total_height,m_total_width;

    int row1_offset, column1_offset, row2_offset, column2_offset, measure_number, value;
    double  right_height_low, right_height_high, right_width_low, right_width_high, left_height_low, left_height_high, left_width_low, left_width_high;
	double total_height_low, total_height_high, total_width_low, total_width_high;

    double  m_ratio;
    HDevProcedure* m_proc_detection;
    HDevProcedureCall* m_call_detection;
    HObject  image_in,region, region_height_show,region_width_show;

    

public:
    explicit MeasureElectrode(QDialog *parent = nullptr, QSettings* qsettings = nullptr,QString section="") ;
    ~MeasureElectrode() ;
    virtual void detectionImage();
    virtual bool detection( HObject image_in, QString& message);
    //virtual bool detection( Mat image_in,QString& message);
    virtual void draw( Mat image_in,Mat& image_out);
    virtual void loadParameter();
    virtual void saveParameter();
    virtual bool showDialog();
    bool sendPLC(const Mat image_in,QString& message);
    void getRect(int x,int y,int width,int height);
};
#pragma execution_character_set("utf-8")
